#include <iostream>
#include <type_traits>

//std::enable_if 具备限定模板参数的作用，可以在编译器检查输入模板参数的有效性
template<class T>
typename std::enable_if<std::is_integral<T>::value, bool>::type //is_integral 必须传入整型 类似的还有 is_floating_point is_pointer etc...
    is_odd(T i) { return bool(i%2); }

template<class T,
    class = typename std::enable_if<std::is_integral<T>::value>::type>
    bool is_even(T i) { return !bool(i % 2); }



/*template<class T>*/
//typename std::enable_if<std::is_arithmetic<T>::value, std::string>::type
//ToString(T & t) { return std::to_string(t); }

//template <class T>
//typename std::enable_if<!std::is_same<T, std::string>::value, std::string>::type
//ToString(T & t) {return t;}

int main(void)
{
    short int i = 1;
    short int r = 2;
    double f = 2.1;

    std::cout << std::boolalpha;
    std::cout << "i is odd: " << is_odd(i) << std::endl;
    std::cout << "i is event: " << is_even(i) << std::endl;

    std::cout << "i is odd: " << is_odd(r) << std::endl;
    std::cout << "i is event: " << is_even(r) << std::endl;
    
    //no matching function for call to 'is_even(double&)'
/*    std::cout << "i is odd: " << is_odd(f) << std::endl;*/
    /*std::cout << "i is event: " << is_even(f) << std::endl;*/



    std::string pi = "pi is" + std::to_string(3.1415926);
    return 0;
}
